package com.pro.service.imple;

import com.pro.dao.UserAuthorityMapper;
import com.pro.entity.Authority;
import com.pro.entity.UserAuthority;
import com.pro.service.UserAuthorityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName: UserAuthorityServiceImple
 * @Author: 笑笑
 * @DATE: 2021/11/11
 * @TIME: 下午 07:35
 */
@Service
public class UserAuthorityServiceImple implements UserAuthorityService {
    @Autowired
    private UserAuthorityMapper userAuthorityMapper;

    //查询所有权限信息
    @Override
    public List<Authority> getAllAuthority() {
        return userAuthorityMapper.getAllAuthority();
    }

    //根据用户id查询权限信息
    @Override
    public List<Authority> getByUserId(Integer id) throws Exception {
        if (id == null || id < 0){
            throw new Exception("id不争取");
        }
        return userAuthorityMapper.getByUserId(id);
    }

    //添加用户权限信息
    @Override
    public Boolean addUserAuthority(UserAuthority userAuthority) {
        return userAuthorityMapper.addUserAuthority(userAuthority);
    }

    //删除用户权限信息
    @Override
    public Boolean DeleteUserAuthority(UserAuthority userAuthority) throws Exception {
        if (userAuthority.getUserId() < 0 || userAuthority.getAuthorityId() < 0){
            throw new Exception("内容错误");
        }
        return userAuthorityMapper.DeleteUserAuthority(userAuthority);
    }
}
